# encoding: utf-8
'''
created on 2014-12-29
@chapter: 4.4.2
@name: 牛顿插值
@author: revol
'''
from algorithms.solve import Solve

class NewtonInt(Solve):
    def __init__(self,data=[]):
        Solve.__init__(self, data)
        self._name=u'牛顿插值'
        self._description=u'牛顿插值'
        self._paramenters=[{'name':'points','type':self.typeLIST},
                           {'name':'x','type':self.typeFLOAT}]

    def f(self,x):
        return self.newtonInt(self._data['points'],x)
        
    def calc(self,data):
        Solve.calc(self, data)
        p=data['points']
        x=data['x']
        self._result=self.newtonint(p, x)
        return self._result
    
    def newtonint(self,p,x):
        n=len(p)
        facts=[1,]
        dqs=[p[0][1],]
        for i in xrange(1,n):
            facts.append((x-p[i-1][0])*facts[i-1])
            dqs.append()
            
    def qd(self,p1,p2):
        u'''
        差商
        '''
        return (p2[1]-p1[1])/(p2[0]-p1[0])
